home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / message / subcls / initmenu.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-06-13  |  2.3 KB  |  74 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Set Menu Caption"
  4.    ClientHeight    =   1860
  5.    ClientLeft      =   1320
  6.    ClientTop       =   2010
  7.    ClientWidth     =   5205
  8.    Height          =   2550
  9.    Left            =   1260
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1860
  12.    ScaleWidth      =   5205
  13.    Top             =   1380
  14.    Width           =   5325
  15.    Begin MsgHook MsgHook 
  16.       Left            =   120
  17.       Top             =   120
  18.    End
  19.    Begin TextBox Text1 
  20.       Height          =   285
  21.       Left            =   120
  22.       TabIndex        =   0
  23.       Text            =   "Enter text here and open File menu"
  24.       Top             =   720
  25.       Width           =   4935
  26.    End
  27.    Begin Menu mnuFile 
  28.       Caption         =   "&File"
  29.       Begin Menu mnuFileText 
  30.          Caption         =   "<<>>"
  31.       End
  32.       Begin Menu mnuFileSep10 
  33.          Caption         =   "-"
  34.       End
  35.       Begin Menu mnuFileExit 
  36.          Caption         =   "E&xit"
  37.       End
  38.    End
  39. Option Explicit
  40. ' Windows contant
  41. Const WM_INITMENUPOPUP = &H117
  42. Sub Form_Load ()
  43.    ' Setup MsgHook
  44.    MsgHook.HwndHook = Me.hWnd
  45.    MsgHook.Message(WM_INITMENUPOPUP) = True
  46. End Sub
  47. Sub mnuFileExit_Click ()
  48.     Unload Me
  49. End Sub
  50. Sub mnuFileText_Click ()
  51.     Dim msg As String
  52.     msg = "This program shows how to change the text of"
  53.     msg = msg & " a menu item at run-time. Note that you"
  54.     msg = msg & " can do this with straight VB in response"
  55.     msg = msg & " to the mnuFile_Click event. However,"
  56.     msg = msg & " doing it this way, the text will get cut"
  57.     msg = msg & " off if it is longer than the currently"
  58.     msg = msg & " longest menu item." & Chr$(13) & Chr$(10)
  59.     msg = msg & Chr$(13) & Chr$(10)
  60.     msg = msg & "Trapping WM_INITPOPUPMENU lets you set"
  61.     msg = msg & " menu text before Windows determines the"
  62.     msg = msg & " width of the menu."
  63.     MsgBox msg
  64. End Sub
  65. Sub MsgHook_Message (msg As Integer, wParam As Integer, lParam As Long, result As Long)
  66.     If msg = WM_INITMENUPOPUP Then
  67.         ' Update menu text if index = 0 (File menu)
  68.         If (lParam And &HFFFF&) = 0 Then
  69.             mnuFileText.Caption = Text1
  70.             result = 0
  71.         End If
  72.     End If
  73. End Sub
  74.